package com.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.demo.ResponseResult;
import com.demo.domain.entity.PersonalInformation;
import com.demo.service.PersonalInformationService;
import com.demo.mapper.PersonalInformationMapper;
import com.demo.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
*
*/
@Service
public class PersonalInformationServiceImpl extends ServiceImpl<PersonalInformationMapper, PersonalInformation>
implements PersonalInformationService{

    @Autowired
    private PersonalInformationMapper personalInformationMapper;
    @Override
    public ResponseResult PersonalInfo() {
        LambdaQueryWrapper<PersonalInformation> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(PersonalInformation::getAccount,SecurityUtils.getLoginUser().getUsername());
        PersonalInformation personalInformation=getOne(queryWrapper);
        if (personalInformation==null){
            PersonalInformation personalInformation1=new PersonalInformation();
            personalInformation1.setAccount(SecurityUtils.getLoginUser().getUsername());
            save(personalInformation1);
             personalInformation=getOne(queryWrapper);
        }
            return ResponseResult.okResult(personalInformation);
    }

    @Override
    public ResponseResult updateInfo(PersonalInformation personalInformation) {
        return ResponseResult.okResult(updateById(personalInformation));
    }

    @Override
    public ResponseResult areainfo() {
        List<String> list= personalInformationMapper.listByUserType();

        return ResponseResult.okResult(list);
    }
}
